package cn.wzy.listenermq;

import cn.wzy.config.RegisterNoticeRabbitmqConfig;
import cn.wzy.dto.RegisterNoticeDto;
import cn.wzy.utils.MailUtils;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class RegisterNoticeEmailReceiveHandler {
    @Resource
    private MailUtils mailUtils;
    //监听email队列
    @RabbitListener(queues = {RegisterNoticeRabbitmqConfig.QUEUE_INFORM_EMAIL})
    public void receive_email(RegisterNoticeDto registerNoticeDto, Message message, Channel channel) {
        String receiver = registerNoticeDto.getReceiver();
        String substring = receiver.substring(receiver.indexOf("/") + 1);
        //email进行发送
        mailUtils.simpleSend("荣车宝注册",registerNoticeDto.getContent(),substring);
    }
}